import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = []
const requireRouter = require.context('../view', true, /index.vue/)

requireRouter.keys().forEach(function(fileName) {
  const componentConfig = requireRouter(fileName)
  const name = fileName.split('/')[1]
  const route = {
    path: '/' + name,
    component: componentConfig
  }
  routes.push(route)
})


const firstRoute = routes[0]
routes.push({
  path: '/',
  redirect: firstRoute.path
})
const router = new Router({ routes })

export default router
